﻿@using FwProject.EventAdvertising.Dto
@model ShopSecondkillBackstageEnterDto
@section styles{
}
<style>
    a {
        text-decoration: none;
    }

    .layui-index {
        padding: 15px;
    }

    .layui-table td, .layui-table th {
        font-size: 14px;
        text-align: center;
    }
</style>
<div class="layui-index">
    <form class="layui-form layui-form-pane" action="@Url.Action("Create")" method="post" novalidate="novalidate" data-ajax="true" data-ajax-success="ReloadAjaxCallbackgoback" data-ajax-failure="FailureAjaxCallback" data-ajax-method="Post" role="form" lay-filter="form1">
        @Html.AntiForgeryToken()
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>秒杀活动</legend>
        </fieldset>
        <div class="layui-form-item">
            @Html.LabelFor(o => o.SecondkillTitle, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.TextBoxFor(o => o.SecondkillTitle, new { @class = "layui-input", @placeholder = "请输入标题" })
                @Html.HiddenFor(o => o.SecondkillTitle)
            </div>
        </div>
        <div class="layui-form-item">
            @Html.LabelFor(o => o.SecondkillDateRange, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.TextBoxFor(o => o.SecondkillDateRange, new { @class = "layui-input" })
            </div>
        </div>
        <div class="layui-form-item">
            @Html.LabelFor(o => o.SecondkillPrice, new { @class = "layui-form-label" })
            <div class="layui-input-inline">
                @Html.TextBoxFor(o => o.SecondkillPrice, new { @class = "layui-input", @lay_verify = "number" })
                @Html.ValidationMessageFor(o => o.SecondkillPrice)
            </div>
        </div>
        <div class="layui-form-item">
            @Html.LabelFor(o => o.SecondkillCount, new { @class = "layui-form-label" })
            <div class="layui-input-inline">
                @Html.TextBoxFor(o => o.SecondkillCount, new { @class = "layui-input", @lay_verify = "number" })
                @Html.ValidationMessageFor(o => o.SecondkillCount)
            </div>
        </div>
        <div class="layui-form-item">
            @Html.LabelFor(o => o.SecondkillSingleCount, new { @class = "layui-form-label" })
            <div class="layui-input-inline">
                @Html.TextBoxFor(o => o.SecondkillSingleCount, new { @class = "layui-input" , @lay_verify = "number" })
                @Html.ValidationMessageFor(o => o.SecondkillSingleCount)
            </div>
        </div>

        <div class="layui-form-item" pane="">
            <label class="layui-form-label">活动商品选择</label>
            <div class="layui-input-block">
                <input type="radio" name="EventGoodsRange" lay-filter="goodsRange" value="All" title="全部商品参与" checked="">
                <input type="radio" name="EventGoodsRange" lay-filter="goodsRange" value="Part" title="部分商品参与">
            </div>
        </div>
        <table class="layui-table" lay-size="lg" id="productlist" style="display:none;">
            <thead>
                <tr>
                    <th>缩略图</th>
                    <th>商品名称</th>
                    <th>商品编号</th>
                    <th>商品分类</th>
                    <th>销售价格</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit="" lay-filter="demo2">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </form>
</div>
@section scripts{
    <script src="~/js/main.js"></script>
    <script type="text/javascript">
        layui.use(['form', 'layedit', 'laydate', 'table', 'layer', 'element', 'upload'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , table = layui.table;

            //日期时间范围
            laydate.render({
                elem: '#SecondkillDateRange'
                , type: 'datetime'
                , range: "~"
                , calendar: true
            });

            form.on('radio(goodsRange)', function (data) {
                //console.log(data.elem); //得到radio原始DOM对象
                //console.log(data.value); //被点击的radio的value值
                if (data.value == "Part") {
                    $("#productlist").show();
                    LayerOpen("商品选择", "@Url.Action("ShopProductSelect")");
                } else {
                    $("#productlist").hide();
                }

            });

        });

        $(document).ready(function () {


        });

        function AddGoods(products) {
            if (products.length > 0) {
                var list = $("#productlist").find("input[name='ShopProductIds']");
                var ids = [];
                    for (var i = 0; i < list.length; i++) {
                        ids.push($(list[i]).val());
                    }
                var boo = true;
                for (var i = 0; i < products.length; i++) {
                        for (var j = 0; j < ids.length; j++) {
                            if (ids[j] == products[i].id) {
                                boo = false;
                            }
                        }

                    if (boo) {
                        var tr = $("<tr>");
                        tr.append("<td><img src='" + products[i].imagePic + "' style='width: 40px; height: 40px;'></td><td>" + products[i].productName + "</td><td>" + products[i].productNumber + "</td><td>" + products[i].productType + "</td><td>" + products[i].price + "</td><td><input type='hidden' name='ShopProductIds' value='" + products[i].id + "'/><button type='button' class='layui-btn layui-btn-small delete'>删除</button></td>");

                        $('#productlist tbody').append(tr);
                    }
                    boo = true;
                }
            }
        }
        function intersect(arr1, arr2) {
            if (Object.prototype.toString.call(arr1) === "[object Array]" && Object.prototype.toString.call(arr2) === "[object Array]") {
                return arr1.filter(function (v) {
                    return arr2.indexOf(v) !== -1
                })
            }
        }
        $("#productlist tbody").on("click", ".delete", function () {
            $(this).parent().parent().remove();
        })

        function ReloadAjaxCallbackgoback(data, successInfo) {
            if (data.success) {
                layer.msg('保存成功！', { time: 2000, end: function () { top.CloseTab(121514) } })
            } else {
                layer.msg('保存失败：' + successInfo);
            }
        }


    </script>
}
